import {Component, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {NewsService} from "../news.service";
import {SettingUrl} from "../../../public/setting/setting_url";
import {Enums} from '../../../public/setting/enums';

@Component({
  selector: 'app-news-detail',
  templateUrl: './news-detail.component.html',
  styleUrls: ['./news-detail.component.css']
})
export class NewsDetailComponent implements OnInit {
  private code: string;
  public newsInfo: any = {};//news信息
  public newsState = Enums.newsState;       // 状态

  constructor(private newsService: NewsService, private route: ActivatedRoute, private router: Router) {
  }

  ngOnInit() {
    this.code = this.route.snapshot.params.code;//获取参数
    this.loadNewsInfo();//查询news类型列表
  }

  /**
   * 查询news信息
   */
  loadNewsInfo() {
    this.newsService.loadNewsByCode(this.code).then((data: any) => {
      if (data) this.newsInfo = data;
    })
  }

  /**
   * 修改未设置数据
   */
  toModifyTheUnSetData() {
    this.router.navigate([SettingUrl.ROUTERLINK.news.modify, this.code])
  }

}
